package com.example.luo;

import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;



public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView            tv;
    private TextView            tv1;
    private TextView            tv2;
    private TextView            tv3;
    private TextView            tv4;
    private LinearLayout        ll;
    private HomeWatcherReceiver mReceiver;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initListener();


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        unregisterReceiver(mReceiver);

    }

    //    再重写onKey事件即可。
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        if (keyCode == KeyEvent.KEYCODE_HOME) {
            Toast.makeText(this, "home", Toast.LENGTH_SHORT).show();
            return true;
        }
        return super.onKeyDown(keyCode, event);

    }

    @Override
    public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
        super.onSaveInstanceState(outState, outPersistentState);
    }

    private void initView() {
        tv = (TextView) findViewById(R.id.tv);
        tv1 = (TextView) findViewById(R.id.tv1);
        tv2 = (TextView) findViewById(R.id.tv2);
        tv3 = (TextView) findViewById(R.id.tv3);
        tv4 = (TextView) findViewById(R.id.tv4);
        ll = (LinearLayout) findViewById(R.id.ll);
    }

    private void initListener() {
        tv1.setOnClickListener(this);
        tv2.setOnClickListener(this);
        tv3.setOnClickListener(this);
        tv4.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv1:
                tv1.setPadding(2, 2, 2, 2);
                tv1.setBackgroundResource(R.drawable.bg1);
                break;
            case R.id.tv2:
                tv2.setBackgroundResource(R.drawable.bg2);
                tv2.setPadding(2, 2, 2, 2);
                break;
            case R.id.tv3:
                tv3.setBackgroundResource(R.drawable.shape3);
//                tv3.setPadding(5,5,5,5);
                break;
            case R.id.tv4:
                //Intent intent = new Intent();
                //intent.setAction("itheima.com.view");
                //startActivity(intent);
//              String str = getResources().getString( R.string.str, 3, "成功的测试");
                String str = getResources().getString(R.string.str);
                String strnew = String.format(str, 2, "测试成功");
                Toast.makeText(getApplicationContext(), strnew, Toast.LENGTH_LONG).show();
                break;
        }
    }
}
